package com.ruoyi.franchise.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.franchise.domain.AdminMenu;
import com.ruoyi.franchise.service.IAdminMenuService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 菜单管理Controller
 * 
 * @author ruoyi
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/adminMenu")
public class AdminMenuController extends BaseController
{
    @Autowired
    private IAdminMenuService adminMenuService;

    /**
     * 查询菜单管理列表
     */
    @RequiresPermissions("franchise:adminMenu:list")
    @GetMapping("/list")
    public TableDataInfo list(AdminMenu adminMenu)
    {
        startPage();
        List<AdminMenu> list = adminMenuService.selectAdminMenuList(adminMenu);
        return getDataTable(list);
    }

    /**
     * 导出菜单管理列表
     */
    @RequiresPermissions("franchise:adminMenu:export")
    @Log(title = "菜单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdminMenu adminMenu)
    {
        List<AdminMenu> list = adminMenuService.selectAdminMenuList(adminMenu);
        ExcelUtil<AdminMenu> util = new ExcelUtil<AdminMenu>(AdminMenu.class);
        util.exportExcel(response, list, "菜单管理数据");
    }

    /**
     * 获取菜单管理详细信息
     */
    @RequiresPermissions("franchise:adminMenu:query")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId)
    {
        return success(adminMenuService.selectAdminMenuByMenuId(menuId));
    }

    /**
     * 新增菜单管理
     */
    @RequiresPermissions("franchise:adminMenu:add")
    @Log(title = "菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdminMenu adminMenu)
    {
        return toAjax(adminMenuService.insertAdminMenu(adminMenu));
    }

    /**
     * 修改菜单管理
     */
    @RequiresPermissions("franchise:adminMenu:edit")
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdminMenu adminMenu)
    {
        return toAjax(adminMenuService.updateAdminMenu(adminMenu));
    }

    /**
     * 删除菜单管理
     */
    @RequiresPermissions("franchise:adminMenu:remove")
    @Log(title = "菜单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Long[] menuIds)
    {
        return toAjax(adminMenuService.deleteAdminMenuByMenuIds(menuIds));
    }
}
